package me.helllp.dake.generator.engine;

import com.squareup.javapoet.JavaFile;
import com.squareup.javapoet.TypeSpec;
import freemarker.template.TemplateException;
import lombok.Getter;
import lombok.Setter;
import me.helllp.dake.generator.meta.ProjectMetaData;

import java.io.File;
import java.io.IOException;

@Getter
@Setter
public class JavaFileGenerator extends AbstractGenerator{
    private String fileName;

    private String basePackage;

    private TypeSpec typeSpec;

    private ProjectMetaData projectMetaData;

    public JavaFileGenerator(ProjectMetaData projectMetaData) {
        this.projectMetaData = projectMetaData;
        this.basePackage = projectMetaData.getBasePackage();
    }

    @Override
    public void generator() throws IOException, TemplateException {
        JavaFile file = JavaFile.builder(basePackage, typeSpec).build();
        file.writeToFile(new File(projectMetaData.getSrcJavaPath()));
    }
}
